package cn.unknowpupil.init.service.gen.impl;

import cn.unknowpupil.init.domain.gen.GenTableColumn;
import cn.unknowpupil.init.mapper.gen.GenTableColumnMapper;
import cn.unknowpupil.init.service.gen.IGenTableColumnService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Created at 2020-11-30 by  w10g <br>
 * Initialize GenTableColumn  ... <br>
 *  代码生成业务表字段 核心业务处理实现类
 *
 * @author unknowpupil
 * @since 0.0.1
 */
@Service
public class GenTableColumnServiceImpl extends ServiceImpl<GenTableColumnMapper, GenTableColumn>implements IGenTableColumnService {


        /**
         *  新增
         * @param genTableColumn {@link GenTableColumn}  代码生成业务表字段
         * @return {@link GenTableColumn}
         */
        @Override
        public  boolean create( GenTableColumn genTableColumn ){
            return save(genTableColumn);
        }

        /**
         *  详情
         * @param id {@code Long}   GenTableColumn ID
         * @return {@link GenTableColumn}
         */
        @Override
        public  GenTableColumn info(Long id){
            return getById(id);
        }

        /**
         *  删除
         * @param ids {@code Long}   ids
         * @return {@link GenTableColumn}
         */
        @Override
        public  boolean delete(Long[] ids){
            List<Long> collect = Stream.of(ids).collect(Collectors.toList());
            return removeByIds(collect);
        }


        /**
         *  修改
         * @param genTableColumn {@link GenTableColumn}  代码生成业务表字段
         * @return {@link GenTableColumn}
         */
        @Override
        public  boolean update( GenTableColumn genTableColumn ){
            return updateById(genTableColumn);
        }


        /**
         * 分页
         * @param current {@code int} 页码
         * @param size {@code int} 笔数
         * @param genTableColumn {@link GenTableColumn}
         * @return {@code IPage<GenTableColumn>}
         */
        @Override
        public IPage<GenTableColumn> page(int current, int size, GenTableColumn genTableColumn){
            IPage<GenTableColumn> page = new Page<>(current, size);
            LambdaQueryWrapper<GenTableColumn> wrapper = new LambdaQueryWrapper<>();
            // TODO 查询
            // TODO 排序
            return super.page(page, wrapper);
        }

    @Override
    public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId) {

        return baseMapper.selectGenTableColumnListByTableId(tableId);
    }

    @Override
    public IPage<GenTableColumn> selectGenTableColumnListByTableId(Long tableId, int current, int size) {
        IPage<GenTableColumn> page = new Page<>(current, size);
        return baseMapper.selectGenTableColumnPageByTableId(page,tableId);
    }

}
